import { WebsocketProvider } from "y-websocket";
import * as Y from "yjs";

const doc = new Y.Doc();

const provider = new WebsocketProvider(
  "ws://www.ruiyangz.top:5000",
  "docs-1",
  doc,
  { connect: false },
);

provider.on("sync", () => {
  console.log(doc.getXmlFragment("docs-1"));
  console.log("Document structure:", doc.toJSON());
});

import { useEffect } from "react";

import { DocEditor } from "./DocEditor";
export const Doc = () => {
  useEffect(() => {
    provider.connect();

    return () => provider.disconnect();
  }, []);

  return (
    <>
      {/* <DocEditor pageId='1' doc={doc} provider={provider} /> */}
      <DocEditor doc={doc} provider={provider} />
    </>
  );
};
